//
//  BApplyForMoneyDetailCell.m
//  DistributorAB
//
//  Created by LZY on 2019/10/8.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "BApplyForMoneyDetailCell.h"
#import "BGoodsInfoModel.h"
#import "ZGrantDetailModel.h"

@interface BApplyForMoneyDetailCell ()
@property (nonatomic, strong) UILabel *lblAddress;//所在区域
@property (nonatomic, strong) UILabel *lblName;//名称
@property (nonatomic, strong) UILabel *lblPhone;//电话
@property (nonatomic, strong) UILabel *lblCreatTime;//出厂时间
@property (nonatomic, strong) UILabel *lblInstallTime;//安装时间
@property (nonatomic, strong) UILabel *lblDamageTime;//损坏时间
@property (nonatomic, strong) UILabel *lblGoodsCategory;//配件品类
@property (nonatomic, strong) UILabel *lblGoodsName;//配件名称
@property (nonatomic, strong) UILabel *lblGoodsEffectiveTime;//有效期
@property (nonatomic, strong) UILabel *lblGoodsQualityTime;//质保期
@property (nonatomic, strong) UILabel *lblGoodsPay;//赔付金额
@end

@implementation BApplyForMoneyDetailCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupViewAction];
    }
    return self;
}
#pragma mark - 界面布局方法
- (void)setupViewAction{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = kColorWithHex(0xf2f2f2);
    
    NSInteger addressHeight = 0;
    if (AGENT_LEVEL == 1) {
        addressHeight = 34;
    }
    
    UIView *viewBg = [[UIView alloc] initWithFrame:CGRectMake(0, 2, kScreen_Width, 430 + addressHeight)];
    viewBg.backgroundColor = kColorWithHex(0xffffff);
    [self.contentView addSubview:viewBg];
    
    if (AGENT_LEVEL == 1) {
        UILabel *lblNoticeAddress = [[UILabel alloc] initWithFrame:CGRectMake(25, 10, 60, 34)];
        lblNoticeAddress.text = @"所在地区";
        lblNoticeAddress.font = [UIFont systemFontOfSize:14];
        lblNoticeAddress.textColor = kColorWithHex(0x666666);
        [viewBg addSubview:lblNoticeAddress];
        _lblAddress = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, kScreen_Width - 110, 34)];
        _lblAddress = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, kScreen_Width - 110, 34)];
        _lblAddress.textColor = kColorWithHex(0x666666);
        _lblAddress.font = [UIFont boldSystemFontOfSize:14];
        [viewBg addSubview:_lblAddress];
    }
    
    UILabel *lblNoticeName = [[UILabel alloc] initWithFrame:CGRectMake(25, 10 + addressHeight, 60, 34)];
    lblNoticeName.text = @"师傅姓名";
    lblNoticeName.font = [UIFont systemFontOfSize:14];
    lblNoticeName.textColor = kColorWithHex(0x666666);
    [viewBg addSubview:lblNoticeName];
    _lblName = [[UILabel alloc] initWithFrame:CGRectMake(100, 10 + addressHeight, kScreen_Width - 110, 34)];
    _lblName.textColor = kColorWithHex(0x666666);
    _lblName.font = [UIFont boldSystemFontOfSize:14];
    [viewBg addSubview:_lblName];
    UIView *viewLineOne = [[UIView alloc] initWithFrame:CGRectMake(25, 44 + addressHeight, kScreen_Width - 35, 1)];
    viewLineOne.backgroundColor = kColorWithHex(0xdbdbdb);
    [viewBg addSubview:viewLineOne];
    
    UILabel *lblNoticePhone = [[UILabel alloc] initWithFrame:CGRectMake(25, 45 + addressHeight, 60, 34)];
    lblNoticePhone.text = @"联系电话";
    lblNoticePhone.font = [UIFont systemFontOfSize:14];
    lblNoticePhone.textColor = kColorWithHex(0x666666);
    [viewBg addSubview:lblNoticePhone];
    _lblPhone = [[UILabel alloc] initWithFrame:CGRectMake(100, 45 + addressHeight, kScreen_Width - 110, 34)];
    _lblPhone.textColor = kColorWithHex(0x666666);
    _lblPhone.font = [UIFont boldSystemFontOfSize:14];
    [viewBg addSubview:_lblPhone];
    UIView *viewLineTwo = [[UIView alloc] initWithFrame:CGRectMake(25, 79 + addressHeight, kScreen_Width - 35, 1)];
    viewLineTwo.backgroundColor = kColorWithHex(0xdbdbdb);
    [viewBg addSubview:viewLineTwo];
    
    UILabel *lblNoticeCreat = [[UILabel alloc] initWithFrame:CGRectMake(25, 80 + addressHeight, 60, 34)];
    lblNoticeCreat.text = @"出厂时间";
    lblNoticeCreat.font = [UIFont systemFontOfSize:14];
    lblNoticeCreat.textColor = kColorWithHex(0x666666);
    [viewBg addSubview:lblNoticeCreat];
    _lblCreatTime = [[UILabel alloc] initWithFrame:CGRectMake(100, 80 + addressHeight, kScreen_Width - 110, 34)];
    _lblCreatTime.textColor = kColorWithHex(0x666666);
    _lblCreatTime.font = [UIFont boldSystemFontOfSize:14];
    [viewBg addSubview:_lblCreatTime];
    UIView *viewLineThree = [[UIView alloc] initWithFrame:CGRectMake(25, 114 + addressHeight, kScreen_Width - 35, 1)];
    viewLineThree.backgroundColor = kColorWithHex(0xdbdbdb);
    [viewBg addSubview:viewLineThree];
    
    UILabel *lblNoticeInstall = [[UILabel alloc] initWithFrame:CGRectMake(25, 115 + addressHeight, 60, 34)];
    lblNoticeInstall.text = @"安装时间";
    lblNoticeInstall.font = [UIFont systemFontOfSize:14];
    lblNoticeInstall.textColor = kColorWithHex(0x666666);
    [viewBg addSubview:lblNoticeInstall];
    _lblInstallTime = [[UILabel alloc] initWithFrame:CGRectMake(100, 115 + addressHeight, kScreen_Width - 110, 34)];
    _lblInstallTime.textColor = kColorWithHex(0x666666);
    _lblInstallTime.font = [UIFont boldSystemFontOfSize:14];
    [viewBg addSubview:_lblInstallTime];
    UIView *viewLineFour = [[UIView alloc] initWithFrame:CGRectMake(25, 150 + addressHeight, kScreen_Width - 35, 1)];
    viewLineFour.backgroundColor = kColorWithHex(0xdbdbdb);
    [viewBg addSubview:viewLineFour];
    
    UILabel *lblNoticeDamage = [[UILabel alloc] initWithFrame:CGRectMake(25, 151 + addressHeight, 60, 34)];
    lblNoticeDamage.text = @"损坏时间";
    lblNoticeDamage.font = [UIFont systemFontOfSize:14];
    lblNoticeDamage.textColor = kColorWithHex(0x666666);
    [viewBg addSubview:lblNoticeDamage];
    _lblDamageTime = [[UILabel alloc] initWithFrame:CGRectMake(100, 151 + addressHeight, kScreen_Width - 110, 34)];
    _lblDamageTime.textColor = kColorWithHex(0x666666);
    _lblDamageTime.font = [UIFont boldSystemFontOfSize:14];
    [viewBg addSubview:_lblDamageTime];
    UIView *viewLineFive = [[UIView alloc] initWithFrame:CGRectMake(25, 185 + addressHeight, kScreen_Width - 35, 1)];
    viewLineFive.backgroundColor = kColorWithHex(0xdbdbdb);
    [viewBg addSubview:viewLineFive];
    
    UIView *viewBox = [[UIView alloc] initWithFrame:CGRectMake(10, 212 + addressHeight, kScreen_Width - 20, 199)];
    viewBox.layer.borderWidth = 1;
    viewBox.layer.borderColor = kColorWithHex(0x70be68).CGColor;
    viewBox.layer.cornerRadius = 12;
    viewBox.layer.masksToBounds = YES;
    [viewBg addSubview:viewBox];
    
    UILabel *lblNoticeCategory = [[UILabel alloc] initWithFrame:CGRectMake(15, 22, 60, 32)];
    lblNoticeCategory.text = @"配件品类";
    lblNoticeCategory.font = [UIFont systemFontOfSize:14];
    lblNoticeCategory.textColor = kColorWithHex(0x666666);
    [viewBox addSubview:lblNoticeCategory];
    _lblGoodsCategory = [[UILabel alloc] initWithFrame:CGRectMake(105, 22, viewBox.width - 115, 32)];
    _lblGoodsCategory.font = [UIFont boldSystemFontOfSize:14];
    _lblGoodsCategory.textColor = kColorWithHex(0x333333);
    [viewBox addSubview:_lblGoodsCategory];
    UIView *viewBoxLineOne = [[UIView alloc] initWithFrame:CGRectMake(15, 54, viewBox.width - 15, 1)];
    viewBoxLineOne.backgroundColor = kColorWithHex(0xdbdbdb);
    [viewBox addSubview:viewBoxLineOne];
    
    UILabel *lblNoticeGoodsName = [[UILabel alloc] initWithFrame:CGRectMake(15, 55, 60, 32)];
    lblNoticeGoodsName.text = @"配件名称";
    lblNoticeGoodsName.font = [UIFont systemFontOfSize:14];
    lblNoticeGoodsName.textColor = kColorWithHex(0x666666);
    [viewBox addSubview:lblNoticeGoodsName];
    _lblGoodsName = [[UILabel alloc] initWithFrame:CGRectMake(105, 55, viewBox.width - 115, 32)];
    _lblGoodsName.font = [UIFont boldSystemFontOfSize:14];
    _lblGoodsName.textColor = kColorWithHex(0x333333);
    [viewBox addSubview:_lblGoodsName];
    UIView *viewBoxLineTwo = [[UIView alloc] initWithFrame:CGRectMake(15, 87, viewBox.width - 15, 1)];
    viewBoxLineTwo.backgroundColor = kColorWithHex(0xdbdbdb);
    [viewBox addSubview:viewBoxLineTwo];
    
    UILabel *lblNoticeGoodsEffective = [[UILabel alloc] initWithFrame:CGRectMake(15, 88, 60, 32)];
    lblNoticeGoodsEffective.text = @"有效期";
    lblNoticeGoodsEffective.font = [UIFont systemFontOfSize:14];
    lblNoticeGoodsEffective.textColor = kColorWithHex(0x666666);
    [viewBox addSubview:lblNoticeGoodsEffective];
    _lblGoodsEffectiveTime = [[UILabel alloc] initWithFrame:CGRectMake(105, 88, viewBox.width - 115, 32)];
    _lblGoodsEffectiveTime.font = [UIFont boldSystemFontOfSize:14];
    _lblGoodsEffectiveTime.textColor = kColorWithHex(0x333333);
    [viewBox addSubview:_lblGoodsEffectiveTime];
    UIView *viewBoxLineThree = [[UIView alloc] initWithFrame:CGRectMake(15, 120, viewBox.width - 15, 1)];
    viewBoxLineThree.backgroundColor = kColorWithHex(0xdbdbdb);
    [viewBox addSubview:viewBoxLineThree];
    
    UILabel *lblNoticeGoodsQuality = [[UILabel alloc] initWithFrame:CGRectMake(15, 121, 60, 32)];
    lblNoticeGoodsQuality.text = @"质保期";
    lblNoticeGoodsQuality.font = [UIFont systemFontOfSize:14];
    lblNoticeGoodsQuality.textColor = kColorWithHex(0x666666);
    [viewBox addSubview:lblNoticeGoodsQuality];
    _lblGoodsQualityTime = [[UILabel alloc] initWithFrame:CGRectMake(105, 121, viewBox.width - 115, 32)];
    _lblGoodsQualityTime.font = [UIFont boldSystemFontOfSize:14];
    _lblGoodsQualityTime.textColor = kColorWithHex(0x333333);
    [viewBox addSubview:_lblGoodsQualityTime];
    UIView *viewBoxLineFour = [[UIView alloc] initWithFrame:CGRectMake(15, 153, viewBox.width - 15, 1)];
    viewBoxLineFour.backgroundColor = kColorWithHex(0xdbdbdb);
    [viewBox addSubview:viewBoxLineFour];
    
    UILabel *lblNoticeGoodsPay = [[UILabel alloc] initWithFrame:CGRectMake(15, 154, 80, 32)];
    lblNoticeGoodsPay.text = @"补贴工时费";
    lblNoticeGoodsPay.font = [UIFont systemFontOfSize:14];
    lblNoticeGoodsPay.textColor = kColorWithHex(0x666666);
    [viewBox addSubview:lblNoticeGoodsPay];
    _lblGoodsPay = [[UILabel alloc] initWithFrame:CGRectMake(105, 154, viewBox.width - 115, 32)];
    _lblGoodsPay.font = [UIFont boldSystemFontOfSize:14];
    _lblGoodsPay.textColor = kColorWithHex(0x666666);
    [viewBox addSubview:_lblGoodsPay];
    
}
#pragma mark - 数据更新
- (void)setModel:(BGoodsInfoModel *)model{
    if (model) {
        _model = model;
        _lblName.text = model.repairUser.personName;
        _lblPhone.text = model.repairUser.phone;
        _lblCreatTime.text = model.productionDate;
        _lblInstallTime.text = model.anTime;
        _lblDamageTime.text = model.shTime;
        _lblGoodsCategory.text = model.type_name;
        _lblGoodsName.text = model.parts_name;
        if (model.productionDate.length > 0 && model.termValidity.length > 0) {
            _lblGoodsEffectiveTime.text = [NSString stringWithFormat:@"%@至%@",model.productionDate,model.termValidity];
        }else{
            _lblGoodsEffectiveTime.text = [NSString stringWithFormat:@"%@月",model.install];
        }
        _lblGoodsQualityTime.text = [NSString stringWithFormat:@"%@个月",model.warranty];
        _lblGoodsPay.text = [NSString stringWithFormat:@"￥%@",model.compensationPrice];
    }
}
- (void)setGrantDetailModel:(ZGrantDetailModel *)grantDetailModel{
    if (grantDetailModel) {
        _grantDetailModel = grantDetailModel;
        if (AGENT_LEVEL == 1) {
            _lblAddress.text = grantDetailModel.area_name;
        }
        _lblName.text = grantDetailModel.personName;
        _lblPhone.text = grantDetailModel.phone;
        _lblCreatTime.text = grantDetailModel.productionDate;
        _lblInstallTime.text = grantDetailModel.anTime;
        _lblDamageTime.text = grantDetailModel.shTime;
        _lblGoodsCategory.text = [NSString stringWithFormat:@"%@ %@",grantDetailModel.firstName,grantDetailModel.secondName];
        _lblGoodsName.text = grantDetailModel.parts_name;
        if (grantDetailModel.productionDate.length > 0 && grantDetailModel.termValidity.length > 0) {
            _lblGoodsEffectiveTime.text = [NSString stringWithFormat:@"%@至%@",grantDetailModel.productionDate,grantDetailModel.termValidity];
        }else{
            _lblGoodsEffectiveTime.text = [NSString stringWithFormat:@"%@月",grantDetailModel.install];
        }
        _lblGoodsQualityTime.text = [NSString stringWithFormat:@"%@个月",grantDetailModel.warranty];
        _lblGoodsPay.text = [NSString stringWithFormat:@"￥%@",grantDetailModel.compensationPrice];
    }
}
+ (CGFloat)cellHeight{
    if (AGENT_LEVEL == 1) {
        return 466.0;
    }else{
        return 432.0;
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
